package com.yummy.service.impl;

import com.yummy.entity.ShoppingCart;
import com.yummy.mapper.ShoppingCartMapper;
import com.yummy.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yinbo
 */
@Service
public class ShoppingCartServiceImpl implements ShoppingCartService {

	@Autowired
	ShoppingCartMapper cartMapper;

	@Override
	public ShoppingCart getCartsByUserAndDish(Integer userId, Long dishId) {
		ShoppingCart cart = cartMapper.selectByUserAndDish(userId,dishId);
		return cart;
	}

	@Override
	public boolean addCart(ShoppingCart shoppingCart) {
		return cartMapper.insertCart(shoppingCart)>0;
	}

	@Override
	public boolean updateCart(ShoppingCart cart) {
		return cartMapper.updateByPrimaryKey(cart)>0;
	}

	@Override
	public List<ShoppingCart> queryAllByUserAndStore(Integer userId, int storeId) {

		return cartMapper.selectAllByUserAndStore(userId,storeId);
	}

	@Override
	public boolean remove(ShoppingCart cart) {

		return cartMapper.removeCart(cart)>0;
	}

	@Override
	public boolean clearCarts(List<ShoppingCart> cartList) {

		return cartMapper.removeCartsBatch(cartList)>0;
	}
}
